<template>
    <div class="result">
        <div class="search" @click="gotoSearch">
            <div class="cart">
            <van-image
            @click="gotoSearchPage"
            width="16"
            height="16"
            src=""
        />
        </div>
        <van-search class="inp" v-model="value" placeholder="请输入搜索关键词" >
            <template #right-icon>
                <van-image class="img" width="20" height="20" src="" />
            </template>
        </van-search>
        <div class="cart">
            <van-image  width="22" height="21" src="" />
        </div>
        </div>
        <div class="type">
            <div class="type-item" :class="{item:index == 0}" @click="ChangeType(0)">
                综合
            </div>
            <div class="type-item" :class="{item:index == 1}" @click="ChangeType(1)">
                销量
            </div>
            <div class="type-item" :class="{item:index == 2}" @click="ChangeType(2)">
                新品
            </div>
            <div class="type-item" :class="{item:flag}" @click="PriceDropDown()">
                价格
                <van-icon class="type-con" name="arrow-down" size="20" color="#c3c3c3" />
            </div>
            <div class="price" :class="{con:!flag}">
                <div class="price-top">
                    <div class="price-top-text" @click="QuickFindPrice(50,80)">50 <span>-</span> 80</div>
                    <div class="price-top-text" @click="QuickFindPrice(80,90)">80 <span>-</span> 90</div>
                    <div class="price-top-text" @click="QuickFindPrice(90,100)">90 <span>-</span> 100</div>
                </div>
                <div class="price-but">
                    <div class="price-but-left">
                        区间(元)
                    </div>
                    <input type="text" v-model="min">
                    <div class="price-but-center"></div>
                    <input type="text" v-model="max">
                    <div class="price-but-but" @click="seek">
                        确认
                    </div>
                </div>
            </div>
        </div>
        <div class="list">
            <div class="list-item" v-for="s in listed" :key="s.iid" @click="gotodetailed(s.iid)">
                <div class="list-item-img">
                    <van-image width="100%" height="235" :src="s.img" />
                </div>
                <div class="list-item-text">
                    <p class="list-item-text-top">{{ s.props[0] }}</p>
                    <div class="list-item-text-but">
                        <div class="list-item-text-but-left">
                            ¥{{ s.price }}
                        </div>
                        <div class="list-item-text-but-right">
                            {{ s.cfav }}
                            <van-image class="right-img" width="12" height="12" src="" />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
import {SearchResultAPI} from '../../api/home'
export default{
    props:[],
    data(){
        return{
            value:this.$route.query.text,
            //判断选的类型是哪个
            index:0,
            // 价格下拉
            flag:false,
            // 搜索页搜索结果数据
            listed:[],
            // 传过来的搜索名
            text:this.$route.query.text,
            // 搜索类型
            type:'pop',
            // 最低价格默认50
            min:50,
            // 最高价格默认80
            max:80,
        }
    },
    methods:{
        // 改变类型(综合 销量 新品)
        ChangeType(id){
            this.index = id;
            if(id == 0){
                this.type = 'pop'
            }else if(id == 1){
                this.type = 'sell'
            }else if(id == 2){
                this.type = 'new'
            }

            this.SearchResult();
        },
        PriceDropDown(){
            this.flag = !this.flag
        },
        async SearchResult(){
            let url = SearchResultAPI(this.text,this.min,this.text,this.type)
            let {data} = await this.$axios(url);
            this.listed = data.result.wall.docs;
        },
        gotoSearchPage(){
            this.$router.go(-1)
        },
        // 快捷查找合适价格
        QuickFindPrice(min,max){
            this.min = min;
            this.max = max;
            this.SearchResult();
            this.PriceDropDown();
        },
        // 点击确定查找
        seek(){
            this.SearchResult();
            this.PriceDropDown();
        },
        // 跳转到商品详情页
        gotodetailed(id){
            this.$router.push({name: "goods-detail", params: {id: id}});    
        },
        // 跳到搜索页
        gotoSearch(){
            this.$router.push('SearchPage')
        }
    },
    computed:{
        // 传过来的数据
        // list(){
        //     let listed = this.$route.query.list
        //     return JSON.parse(listed)
        // },
        // // 传过来的搜索的东西
        // text(){
        //     return this.$route.query.text
        // }
    },
    mounted(){
        this.SearchResult();
        
    },

}
</script>

<style lang="scss" scoped>
.result{

    .search{
        height: 34px;
        padding: 5px 0px;
        border-bottom: 1px solid #c9c7c8;
        display: flex;
        align-items: center;
        justify-content: space-between; 
        .van-search{
            flex: 1;
            height: 30px;
            background-color: #ececec;
            padding: 0px;
            .van-cell{
                box-sizing: border-box;
                height: 30px;
                background-color: #ececec;
            }
            .van-search__content{
                background-color: #ececec;
            }
        }
        .cart{
            width: 50px;
            height: 45px;
            display: flex;
            align-items: center;
            justify-content: center;
        }
        .inp{
            position: relative;
            .img{
                position: absolute;
                top: 0px;
                right: 0px;
                color: #eeeeee;
            }
        }
    }
    .type{
        height: 40px;
        display: flex;
        align-items: center;
        justify-content: flex-start;
        position: relative;
        .type-item{
            width: 25%;
            font-size: 14px;
            box-sizing: border-box;
            text-align: center;
            position: relative;
            border-left: 1px solid #e6e6e6;
            z-index: 10;
            &.item{
                color: #ef4562;
            }
            .type-con{
                position: absolute;
                right: 10px;
                top: 0px;
                font-weight: 200;
            }
        }
        .price{
            position: absolute;
            left: 0px;
            bottom: -100px;
            width: 100%;
            height: 100px;
            background-color: #fff;
            transition: all .5s;
            opacity: 1;
            z-index: 1000;
            &.con{
                opacity: 0;
                bottom: 0px;
                overflow: hidden;
                height: 0px;
                transition: all .5s;
            }
            .price-top{
                padding: 7.5px 0px 3.75px;
                height: 37.5px;
                display: flex;
                .price-top-text{
                    width: 30%;
                    height: 30px;
                    background-color: #f3f3f3;
                    margin: 2% 0 0 2%;
                    font-size: 14px;
                    color: #333333;
                    line-height: 30px;
                    text-align: center;
                }
            }
            .price-but{
                padding: 0px 7.5px;
                height: 50px;
                display: flex;
                align-items: center;
                justify-content: flex-start;
                .price-but-left{
                    font-size: 14px;
                    color: #333;
                    text-align: center;
                    line-height: 50px;
                }
                input{
                    width: 85px;
                    height: 30px;
                    outline: none;
                    border: 1px solid #e5e5e5;
                    margin: 0px 0px 0px 10px;
                    text-align: center;
                }
                .price-but-center{
                    width: 12px;
                    height: 1px;
                    background-color: #cbcbcb;
                    margin-left: 10px;
                }
                .price-but-but{
                    width: 66px;
                    height: 30px;
                    text-align: center;
                    line-height: 30px;
                    background-color: #ff5b76;
                    color: #fff;
                    font-size: 14px;
                    margin-left: 10px;
                    border-radius: 2px;
                }
            }
        }
    }
    .list{
        padding: 0px 7.5px;
        display: flex;
        background-color: #efefef;
        flex-wrap: wrap;
        align-items: center;
        justify-content: space-between;
        .list-item{
            width: calc((100% - 7.5px) / 2);
            .list-item-img{
                width: 100%;
                height: 235px;
                margin-top: 7.5px;

            }
            .list-item-text{
                padding-top: 7.5px;
                width: 100%;
                background-color: #fff;
                .list-item-text-top{
                    overflow: hidden;
                    text-overflow: ellipsis;
                    display: -webkit-box;
                    -webkit-line-clamp: 2;
                    -webkit-box-orient: vertical;
                    font-size: 12px;
                    color: #333;
                    margin: 0px 9px 2.5px 5px;
                }
                .list-item-text-but{
                    padding: 0px 9px;
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                    .list-item-text-but-left{
                        font-size: 15px;
                        color: #333;
                    }
                    .list-item-text-but-right{
                        color: #999;
                        font-size: 12px;
                        display: flex;
                        align-items: center;
                    }
                }
            }
        }
    }
}
</style>